package com.example.interceptor;

import com.example.util.JJWTUntil;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Description //TODO
 * @Date 2022/9/19 22:58
 * @Author lonng
 **/
@Component
public class LoginInterExecption implements HandlerInterceptor {
    @Autowired
    private JJWTUntil jjwtUntil;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token = request.getHeader("token");
        System.out.println(token);
        if(token.equals("null")&&token.length()==0){
            return false;
        }else{
            Claims claim=jjwtUntil.checkJWT(token);
            Integer uid= (Integer) claim.get("uuid");
            request.setAttribute("uid",uid);
            return true;
        }
    }
}
